import execjs
import os
import json
import requests

headers = {
    "Accept": "application/json, text/plain, */*",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJyZWFnZW50IiwiaWF0IjoxNzQ0NjgyMTkxLCJzdWIiOiI1MzU5MzIyMzcwNzQ0MDc0MjkiLCJleHAiOjE3NDQ3MjUzOTEsInVzZXJfbmFtZSI6IjUzNTkzMjIzNzA3NDQwNzQyOSIsImF0X2lkIjoiNzZDMkFCNTg2ODE5NjM3Mjk4OGMzMjgyNDg0MDQiLCJjbGllbnRfaWQiOiJ3ZWJhcHAiLCJ1cyI6MiwidXQiOjQsInN1cHBJZCI6MTE1NDM2fQ.9ftGT3Y4NiAtvcQdgscXqY6KW_uSGB4ArtsoBKiM22U",
    "Connection": "keep-alive",
    "Content-Type": "application/json",
    "Origin": "https://www.rjmart.cn",
    "Referer": "https://www.rjmart.cn/",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-site",
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36",
    "rjk": "x231.254316112.11744683342534.2126563763.351.4f6280c4f7e44c948c1d412d355c4b86.0.79",
    "sec-ch-ua": '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": '"macOS"',
}

current_dir = os.path.dirname(os.path.abspath(__file__))
js_file_path = os.path.join(current_dir, "test.js")
with open(js_file_path, "r", encoding="utf-8") as f:
    js_content = f.read()
ctx = execjs.compile(js_content)


# token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJyZWFnZW50IiwiaWF0IjoxNzQ0NjgyMTkxLCJzdWIiOiI1MzU5MzIyMzcwNzQ0MDc0MjkiLCJleHAiOjE3NDQ3MjUzOTEsInVzZXJfbmFtZSI6IjUzNTkzMjIzNzA3NDQwNzQyOSIsImF0X2lkIjoiNzZDMkFCNTg2ODE5NjM3Mjk4OGMzMjgyNDg0MDQiLCJjbGllbnRfaWQiOiJ3ZWJhcHAiLCJ1cyI6MiwidXQiOjQsInN1cHBJZCI6MTE1NDM2fQ.9ftGT3Y4NiAtvcQdgscXqY6KW_uSGB4ArtsoBKiM22U"
token = ""
user_flag = "4f6280c4f7e44c948c1d412d355c4b86"


url = "https://gateway.rjmart.cn/store/cart/getProductDetail"
req_config = {"productId": "200206777548", "supplierId": 115436}
req_json = json.dumps(req_config)
time_stamp = 1744684304107
rjk = ctx.call("get_rjk", token, user_flag, req_json, time_stamp)
print(rjk)
# headers["rjk"] = rjk
# data = json.dumps(req_config, separators=(",", ":"))
# response = requests.post(url, headers=headers, data=data)

# print(response.json())
